package cn.pli.bike.ui;

import android.animation.ValueAnimator;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.animation.LinearInterpolator;

import com.framemodule.base.BaseActivityPresenter;
import com.framemodule.base.netstatus.NetUtils;

import cn.pli.bike.R;
import cn.pli.bike.bean.HttpResult;
import cn.pli.bike.bean.UserBean;
import cn.pli.bike.model.UserModel;
import cn.pli.bike.model.http.ApiException;
import cn.pli.bike.model.subscribers.ProgramSubscriber;
import cn.pli.bike.utils.AppUtils;
import cn.pli.bike.utils.CommonUtils;

/**
 * 实名认证
 */
public class UserAuthActivity extends BaseActivityPresenter<UserAuthDelegate> implements View.OnClickListener {
    private String name, verificationCode;

    @Override
    protected void initModel() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


    }

    @Override
    protected void onNetworkConnected(NetUtils.NetType type) {

    }

    @Override
    protected void onNetworkDisConnected() {

    }

    @Override
    protected void bindEvenListener() {
        super.bindEvenListener();
        viewDelegate.setOnClickListener(this, R.id.iv_title_back, R.id.bt_commit);


    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_title_back:
                finish();
                break;

            case R.id.bt_commit:
                name = viewDelegate.getEtName().getText().toString().trim();
                verificationCode = viewDelegate.getEtVerification().getText().toString().trim();

                if (com.framemodule.utils.CommonUtils.isEmpty(name)) {
                    viewDelegate.toast("姓名不能为空");
                    return;
                }
                if (com.framemodule.utils.CommonUtils.isEmpty(verificationCode)) {
                    viewDelegate.toast("身份证号不能为空");
                    return;
                }
                cardCheckIDCard(name, verificationCode);

                break;
        }

    }


    /**
     * 身份验证
     *
     * @param
     */
    private void cardCheckIDCard(String name, String id) {
        UserModel.cardCheckIDCard(new ProgramSubscriber<HttpResult<String>>() {
            @Override
            public void onNext(HttpResult<String> stringHttpResult) {
                if (viewDelegate != null) {
                    viewDelegate.toast(stringHttpResult.getData());
                    finish();
                }
            }

            @Override
            public void onErr(ApiException e) {
                super.onErr(e);
                finish();
            }
        }, name, id);
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                finish();

            }
        }).start();
        viewDelegate.toast(getString(R.string.message_has_commit));
    }


}
